package main

import (
	"2301house/config"
	"2301house/consts"
	"2301house/inits"
	"2301house/internal/dao"
	"2301house/internal/model"
	"2301house/internal/queue"
	"encoding/json"
	"github.com/gin-gonic/gin"
	"log"
)

func main() {
	config.Init()
	inits.MysqlInits()
	inits.InitRabbitMq()

	router := gin.Default()
	router.Run(":9999") // 监听并在 0.0.0.0:9999 上启动服务
	msgs := queue.QueueSub(consts.QUEUE)

	forever := make(chan bool)
	//启用协程处理消息
	go func() {
		for d := range msgs {
			//消息逻辑处理，可以自行设计逻辑
			log.Printf("Received a message: %s", d.Body)
			var data model.ChatHistory
			_ = json.Unmarshal(d.Body, &data)
			dao.Create(&data)

		}
	}()

	log.Printf(" [*] Waiting for messages. To exit press CTRL+C")
	<-forever
}
